package com.example.collect.export.mapper;

import com.example.collect.export.model.DbTable;
import com.example.collect.export.model.DbTableField;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


@Mapper
public interface CustomMapper {

    @Select({"select table_name as tableName,table_comment as comment from information_schema.tables where table_schema =#{dbName} order by table_name"})
    List<DbTable> getAllTables(@Param("dbName") String dbName);

    @Select("SELECT COLUMN_NAME AS name,COLUMN_COMMENT AS remark,DATA_TYPE AS type,CHARACTER_MAXIMUM_LENGTH AS length,IF(IS_NULLABLE = 'YES',TRUE,FALSE) AS required\n" +
            "FROM information_schema.COLUMNS WHERE table_name = #{tableName} AND TABLE_SCHEMA = #{dbName};")
    List<DbTableField> getAllFields(@Param("dbName") String dbName, @Param("tableName") String tableName);
}
